# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contriburot: Nícolas F. R. A. Prado <n at nfraprado dot net>

pkgbase=public-inbox
pkgname=(lei perl-publicinbox)
pkgver=1.9.0
pkgrel=1
pkgdesc='An "archives first" approach to mailing lists'
arch=('any')
url="https://public-inbox.org"
license=('AGPL')
depends=(perl perl-inline-c perl-dbd-sqlite perl-uri perl-search-xapian)
makedepends=('git')
source=("https://public-inbox.org/public-inbox.git/snapshot/public-inbox-${pkgver}.tar.gz")
sha256sums=('10d9d3d982bbae9383208f53aa2118482a799a958e9f1b24792b807fc225aaba')

# TODO(Foxboron): Add publicinbox, but perl-plack needs quite a few more packages
#		  lei mirror doesn't work.

build() {
	cd "${pkgbase}-${pkgver}"
	unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
	export PERL_MM_USE_DEFAULT=1 PERL_AUTOINSTALL=--skipdeps
	/usr/bin/perl Makefile.PL INSTALLDIRS=vendor
	make
}

check() {
	cd "${pkgbase}-${pkgver}"
	unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
	export PERL_MM_USE_DEFAULT=1
	#make check
}

package_perl-publicinbox() {
	cd "${pkgbase}-${pkgver}"
	pkgdesc='The perl library for public-inbox'
	unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
	make INSTALLDIRS=vendor DESTDIR="$pkgdir/" install

	rm -rf $pkgdir/usr/bin/vendor_perl \
	       $pkgdir/usr/share/man/*/public-inbox* \
	       $pkgdir/usr/share/man/*/lei*
}

package_lei() {
	cd "${pkgbase}-${pkgver}"
	depends=('perl-publicinbox')
	pkgdesc='The "local email interface" from public-inbox'

	unset PERL5LIB PERL_MM_OPT PERL_LOCAL_LIB_ROOT
	make INSTALLDIRS=vendor DESTDIR="$pkgdir/" install

	install -Dm644 contrib/completion/lei-completion.bash "$pkgdir/usr/share/bash-completion/completions/lei"

	rm -rf $pkgdir/usr/bin/vendor_perl/public-inbox* \
	       $pkgdir/usr/share/perl5 \
	       $pkgdir/usr/lib/perl5 \
	       $pkgdir/usr/bin/site_perl/public-inbox* \
	       $pkgdir/usr/share/man/*/public-inbox* \
	       $pkgdir/usr/share/man/*/PublicInbox*
}
